package com.sevlet;

import com.Bean.Room;
import com.Bean.RoomList;
import com.Bean.VoBean.OrderVo;
import com.dao.OrderDao;
import com.dao.RoomDao;
import com.dao.impl.OrderDaoimpl;
import com.dao.impl.RoomDaoimpl;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.util.JsonUtil;
import com.util.PageUtil;
import com.util.ProxyUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@WebServlet("/OrderServlet.do")

public class OrderServlet extends BaseSevlet {

        public void query(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                OrderDao orderDao=(OrderDao) ProxyUtil.getDaoProxy(new OrderDaoimpl());
                resp.setContentType("text/html;charset=utf-8");

                String lid = req.getParameter("lid");
                String pname = req.getParameter("pname");

                String startdate = req.getParameter("startdate");
                String enddate = req.getParameter("enddate");
                String creatdate = req.getParameter("creatdate");


                String rtid = req.getParameter("rtid");
                String ltype = req.getParameter("ltype");

                String lin_status = req.getParameter("lin_status");
                String out_status = req.getParameter("out_status");


                PrintWriter out = resp.getWriter();
                JsonUtil jsonUtil =new JsonUtil();
                String currentPage = req.getParameter("currentPage");
                String pageSize = req.getParameter("pageSize");

                int i=  Integer.parseInt(currentPage);
                int j=   Integer.parseInt(pageSize);
                OrderVo orderVo = new OrderVo();
                SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
                if (!"".equals(creatdate)&&creatdate!=null){
                        try {
                                Date date = simpleDateFormat.parse(creatdate);
                                orderVo.setLdate(date);
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                }

                if ((!"".equals(startdate)&& startdate!=null) && (!"".equals(enddate) && enddate!=null)){
                        try {
                                Date startime= simpleDateFormat.parse(startdate);
                                Date endtime= simpleDateFormat.parse(enddate);
                                orderVo.setIntime(startime);
                                orderVo.setOuttime(endtime);
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                }
                orderVo.setLid(lid);
                orderVo.setPname(pname);
                orderVo.setRtid(rtid);
                orderVo.setLtype(ltype);
                orderVo.setLin_status(lin_status);
                orderVo.setOut_status(out_status);
                try {
                        PageUtil<OrderVo> orderVoPageUtil = orderDao.queryDataPage(i, j, orderVo);
                        jsonUtil.setMsg("ok");
                        jsonUtil.setData(orderVoPageUtil);
                } catch (Exception e) {
                        e.printStackTrace();
                        jsonUtil.setCode(1);
                        jsonUtil.setMsg("系统错误");
                }
                GsonBuilder gsonBuilder = new GsonBuilder();
                Gson gson = gsonBuilder.create();
                String jsonstr = gson.toJson(jsonUtil);
                out.write(jsonstr);

        }
        public void queryToday(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                System.out.println(111);
                OrderDao orderDao=(OrderDao) ProxyUtil.getDaoProxy(new OrderDaoimpl());
                resp.setContentType("text/html;charset=utf-8");

                String lid = req.getParameter("lid");
                String pname = req.getParameter("pname");

                String nowdate = req.getParameter("nowdate");
                String yulidate = req.getParameter("yulidate");
                String creatdate = req.getParameter("creatdate");
                System.out.println(creatdate);

                String rtid = req.getParameter("rtid");
                String ltype = req.getParameter("ltype");

                String lin_status = req.getParameter("lin_status");
                String out_status = req.getParameter("out_status");


                PrintWriter out = resp.getWriter();
                JsonUtil jsonUtil =new JsonUtil();
                String currentPage = req.getParameter("currentPage");
                String pageSize = req.getParameter("pageSize");

                int i=  Integer.parseInt(currentPage);
                int j=   Integer.parseInt(pageSize);
                OrderVo orderVo = new OrderVo();
                SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");

                if (!"".equals(creatdate)&&creatdate!=null){
                        try {
                                Date date = simpleDateFormat.parse(creatdate);
                                orderVo.setLdate(date);
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                }
                if (!"".equals(nowdate)&&nowdate!=null){
                        try {
                                Date date = simpleDateFormat.parse(nowdate);
                                orderVo.setIntime(date);
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                }

                if (!"".equals(yulidate)&& yulidate!=null){
                        try {
                                Date date = simpleDateFormat.parse(yulidate);
                                orderVo.setOuttime(date);
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                }

                orderVo.setLid(lid);
                orderVo.setPname(pname);
                orderVo.setRtid(rtid);
                orderVo.setLtype(ltype);
                orderVo.setLin_status(lin_status);
                orderVo.setOut_status(out_status);
                try {
                        PageUtil<OrderVo> orderVoPageUtil = orderDao.queryDataPageToday(i, j, orderVo);
                        jsonUtil.setMsg("ok");
                        jsonUtil.setData(orderVoPageUtil);
                } catch (Exception e) {
                        e.printStackTrace();
                        jsonUtil.setCode(1);
                        jsonUtil.setMsg("系统错误");
                }
                GsonBuilder gsonBuilder = new GsonBuilder();
                Gson gson = gsonBuilder.create();
                String jsonstr = gson.toJson(jsonUtil);
                out.write(jsonstr);

        }


        public void queryLtype(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                OrderDao orderDao=(OrderDao) ProxyUtil.getDaoProxy(new OrderDaoimpl());
                resp.setContentType("text/html;charset=utf-8");
                PrintWriter out = resp.getWriter();
                JsonUtil jsonUtil =new JsonUtil();

                try {
                        List<OrderVo> orderVos = orderDao.queryData(null);
                        jsonUtil.setMsg("ok");
                        jsonUtil.setData(orderVos);
                } catch (Exception e) {
                        e.printStackTrace();
                        jsonUtil.setCode(1);
                        jsonUtil.setMsg("系统错误");
                }
                GsonBuilder gsonBuilder = new GsonBuilder();
                Gson gson = gsonBuilder.create();
                String jsonstr = gson.toJson(jsonUtil);
                out.write(jsonstr);

        }
        public void queryinstatu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                OrderDao orderDao=(OrderDao) ProxyUtil.getDaoProxy(new OrderDaoimpl());
                resp.setContentType("text/html;charset=utf-8");
                PrintWriter out = resp.getWriter();
                JsonUtil jsonUtil =new JsonUtil();

                try {
                        List<OrderVo> orderVos = orderDao.queryDatalin_status(null);
                        jsonUtil.setMsg("ok");
                        jsonUtil.setData(orderVos);
                } catch (Exception e) {
                        e.printStackTrace();
                        jsonUtil.setCode(1);
                        jsonUtil.setMsg("系统错误");
                }
                GsonBuilder gsonBuilder = new GsonBuilder();
                Gson gson = gsonBuilder.create();
                String jsonstr = gson.toJson(jsonUtil);
                out.write(jsonstr);

        }
        public void queryoutstatu(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

                OrderDao orderDao=(OrderDao) ProxyUtil.getDaoProxy(new OrderDaoimpl());
                resp.setContentType("text/html;charset=utf-8");
                PrintWriter out = resp.getWriter();
                JsonUtil jsonUtil =new JsonUtil();

                try {
                        List<OrderVo> orderVos = orderDao.queryDataout_status(null);
                        jsonUtil.setMsg("ok");
                        jsonUtil.setData(orderVos);
                } catch (Exception e) {
                        e.printStackTrace();
                        jsonUtil.setCode(1);
                        jsonUtil.setMsg("系统错误");
                }
                GsonBuilder gsonBuilder = new GsonBuilder();
                Gson gson = gsonBuilder.create();
                String jsonstr = gson.toJson(jsonUtil);
                out.write(jsonstr);

        }
}
 
 
 

